import cx_Oracle as orcl
from . import CONFIG
sql = {
    'username':CONFIG.USERNAME,
    'passwd':CONFIG.PASSWD,
    'host':CONFIG.HOST,
    'port':CONFIG.PORT,
    'sid':CONFIG.SID,
    'sql_sql':CONFIG.SQL_SQL

}



def sql_query(sql):
    """

    :param sql:
    {username:,passwd:,host:,port:,sid:,sql:}
    :return:
    """

    username = sql['username']
    passwd = sql['passwd']
    host = sql['host']
    port = sql['port']
    sid = sql['sid']
    sql_sql = sql['sql']

    # Connect database
    dsn = orcl.makedsn(host, port, sid)
    con = orcl.connect(username, passwd, dsn)
    # Initialization cursor
    cursor = con.cursor()

    cursor.execute(sql_sql)

    result = cursor.fetchall()

    cursor.close()
    con.close()
    return result


